package cn.demoncat.util.web.entity;

import cn.demoncat.util.lang.JsonUtil;
import cn.demoncat.util.lang.constant.StatusConstant.Common;
import cn.demoncat.util.web.constant.TokenTypeEnum;

/**
 * Token拦截消息(访问WEB项目并进行Token拦截时，打印的日志消息)
 * 
 * @author 延晓磊
 *
 * @since 2018年5月4日
 */
public class TokenLog {

	// 日志消息
	private String msg;
	// 日志类型
	private String type;
	// 请求ID
	private String id;
	// 请求IP
	private String ip;
	// 请求用户
	private Long user;
	// 客户端Token
	private String token;
	// 请求来源
	private String referer;
	// 请求方式
	private String method;
	// 请求uri
	private String uri;
	// 请求类型：1 内部REST请求，0 WEB接口请求
	private String rest;
	// 用户代理信息（浏览器和设备）
	private Agent agent;

	public TokenLog() {
		super();
	}

	public TokenLog(TokenTypeEnum type, Access access) {
		super();
		this.msg = type.getMsg();
		this.type = type.getKey();
		this.id = access.getId();
		this.ip = access.getIp();
		this.user = access.getUserId();
		this.token = access.getCtoken();
		this.referer = access.getReferer();
		this.method = access.getMethod();
		this.uri = access.getUri();
		this.rest = access.getIsRest() ? Common.YES : Common.NO;
		this.agent = access.getAgent();
	}

	@Override
	public String toString() {
		return JsonUtil.toStr(this);
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Long getUser() {
		return user;
	}

	public void setUser(Long user) {
		this.user = user;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getReferer() {
		return referer;
	}

	public void setReferer(String referer) {
		this.referer = referer;
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	public Agent getAgent() {
		return agent;
	}

	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	public String getRest() {
		return rest;
	}

	public void setRest(String rest) {
		this.rest = rest;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	
}
